<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<h:head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

	<link rel="stylesheet" href="../../css/bootstrap.min.css" />
	<title><h:outputText value="NP Pillar" /></title>
</h:head>
<h:body>

	<ui:insert name="header">
		<ui:include src="../template/header.xhtml" />
	</ui:insert>
	<ui:insert name="dialog">
		<ui:include src="../template/dialog.xhtml" />
	</ui:insert>
	<h:form id="mainForm">
		<p:panel
			header="#{subjectControler.addMode? 'Add Article Subject' : 'Edit Article Subject'}"
			rendered="#{!subjectControler.browseMode}">
			<p:panelGrid columns="2">
				<p:outputLabel value="Subject:" />
				<p:inputText value="#{subjectControler.editDto.name}"
					required="true" requiredMessage="Subject Name is required."
					validator="#{subjectControler.nameValidate}" />
			</p:panelGrid>
			<p:messages autoUpdate="true" closable="true" />
			<p:commandButton value="Save"
				actionListener="#{subjectControler.apply}" update="mainForm" />
			<p:commandButton value="Cancel" immediate="true"
				actionListener="#{subjectControler.clear}" update="mainForm" />
		</p:panel>
		<p:panel header="Article Subject">
			<p:commandButton value="Add"
				rendered="#{subjectControler.browseMode}"
				actionListener="#{subjectControler.startAdd}" update="mainForm" />

			<p:commandButton value="Delete"
				rendered="#{subjectControler.browseMode}"
				onclick="PF('deleteConfirm_w').show();"
				actionListener="#{subjectControler.startDelete}"
				update="deleteConfirm" />
			<p:spacer />
			<p:dataTable id="subjectTable" value="#{subjectControler.listModel}"
				var="subject" selection="#{subjectControler.selecteds}" rows="10"
				first="#{subjectControler.first}">
				<p:column style="width:1%;text-align: center"
					selectionMode="multiple">
				</p:column>
				<p:column style="width:10%;text-align: center"
					sortBy="#{subject.name}">
					<f:facet name="header">
						<h:outputText value="Article Subject" />
					</f:facet>
					<p:commandLink value="#{subject.name}"
						actionListener="#{subjectControler.startEdit}" update=":mainForm">
						<f:attribute name="subject" value="#{subject}" />
					</p:commandLink>
				</p:column>
			</p:dataTable>
		</p:panel>
		<p:confirmDialog id="deleteConfirm" widgetVar="deleteConfirm_w"
			message="Are you sure to delete these article subject?"
			visible="#{subjectControler.deleteMode}"
			header="NP Pillar - Confirm Required" severity="alert">
			<p:focus context="deleteConfirm" for="cancelBtn" />
			<p:commandButton id="confirmBtn" value="OK" update="mainForm"
				onclick="PF('deleteConfirm_w').hide();"
				actionListener="#{subjectControler.delete}" />
			<p:commandButton id="cancelBtn" value="Cancel"
				actionListener="#{subjectControler.endDelete}" immediate="true"
				onclick="PF('deleteConfirm_w').hide();" />
		</p:confirmDialog>
	</h:form>
</h:body>
</html>
